package hk.m4s.lr.repair.test.ui.adapter;

import android.content.Context;
import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import hk.m4s.lr.repair.test.R;
import hk.m4s.lr.repair.test.model.ClassificationModel;
import hk.m4s.lr.repair.test.model.MaintenanceInfoModel;
import hk.m4s.lr.repair.test.model.projectModle;

/**
 * Created by qi.wang on 2018/1/4.
 */

public class MenuAdapter extends BaseAdapter {
    List<ClassificationModel> list = new ArrayList<>();
    Context context;
    LayoutInflater inflater;
    public int flag=-1;
    public MenuAdapter(Context context, List<ClassificationModel> data) {
        this.context = context;
        this.list = data;
        inflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            holder = new ViewHolder();
            convertView = inflater.inflate(R.layout.list_item_classifi_select, parent, false);
            holder.tipsName = (TextView) convertView.findViewById(R.id.jiangli_name);
            holder.bgLin= (LinearLayout) convertView.findViewById(R.id.bgLay);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        ClassificationModel businessModel = list.get(position);
        holder.tipsName.setText(businessModel.getName());
        if(flag==position){
            holder.bgLin.setBackgroundColor(Color.parseColor("#00000000"));
            holder.tipsName.setTextColor(Color.parseColor("#ff3b30"));
        }else{
            holder.bgLin.setBackgroundColor(Color.parseColor("#ffffff"));
            holder.tipsName.setTextColor(Color.parseColor("#000000"));
        }
        return convertView;
    }

    public static class ViewHolder {
        TextView tipsName;
        LinearLayout bgLin;
    }
}
